package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppWechatUser;
import com.ruoyi.background.service.IAppWechatUserService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信小程序用户Controller
 *
 * @author susu
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/wechatUser/wechatUser")
public class AppWechatUserController extends BaseController {
    @Autowired
    private IAppWechatUserService appWechatUserService;

    /**
     * 查询微信小程序用户列表
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppWechatUser appWechatUser) {
        startPage();
        List<AppWechatUser> list = appWechatUserService.selectAppWechatUserList(appWechatUser);
        return getDataTable(list);
    }

    /**
     * 导出微信小程序用户列表
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:export')")
    @Log(title = "微信小程序用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppWechatUser appWechatUser) {
        List<AppWechatUser> list = appWechatUserService.selectAppWechatUserList(appWechatUser);
        ExcelUtil<AppWechatUser> util = new ExcelUtil<AppWechatUser>(AppWechatUser.class);
        util.exportExcel(response, list, "微信小程序用户数据");
    }

    /**
     * 获取微信小程序用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appWechatUserService.selectAppWechatUserById(id));
    }

    /**
     * 新增微信小程序用户
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:add')")
    @Log(title = "微信小程序用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppWechatUser appWechatUser) {
        return toAjax(appWechatUserService.insertAppWechatUser(appWechatUser));
    }

    /**
     * 修改微信小程序用户
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:edit')")
    @Log(title = "微信小程序用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppWechatUser appWechatUser) {
        return toAjax(appWechatUserService.updateAppWechatUser(appWechatUser));
    }

    /**
     * 删除微信小程序用户
     */
    @PreAuthorize("@ss.hasPermi('wechatUser:wechatUser:remove')")
    @Log(title = "微信小程序用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appWechatUserService.deleteAppWechatUserByIds(ids));
    }
}
